#include "widget.h"
#include "ui_widget.h"
#include <QTimer>
#include <QDateTime>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //启动定时器
    // timer_id1 = startTimer(1000);
    // timer_id2 = startTimer(2000);

    QTimer *time = new QTimer(this);
    connect(ui->pushButton_begin, &QPushButton::clicked, [=](){
        time->start(1000);
    });

    connect(time, &QTimer::timeout, [=](){
        static int num = 1;
        ui->label_3->setText(QString::number(num++));
    });

    connect(ui->pushButton_end, &QPushButton::clicked, [=](){
        time->stop();
    });

    connect(time, &QTimer::timeout, this, &Widget::TimeUpDate);
}

void Widget::TimeUpDate()
{
    QString str = QDateTime::currentDateTime().toString("yyyy-MM-dd hh::mm::ss");
    ui->label_4->setText(str);
}

Widget::~Widget()
{
    delete ui;
}

// void Widget::timerEvent(QTimerEvent* e)
// {
//     if(e->timerId() == timer_id1)
//     {
//         static int num1 = 1;

//         //lb1每隔一秒加一次
//         ui->label_1->setText(QString::number(num1++));
//     }
//     if(e->timerId() == timer_id2)
//     {
//         static int num1 = 1;

//         //lb1每隔一秒加一次
//         ui->label_2->setText(QString::number(num1++));
//     }
// }
